import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from '../components/Login.vue'
import success from '../components/Success.vue'
import Home from '../components/Home.vue'
import Welcome from '../components/Welcome.vue'
import User from '../components/admin/User.vue'
import Goods from '../components/Goods.vue'
import Spo from '../components/Picture'
import Muc from '../components/Music'
import Eu from "../components/Eu";
import Fri from "../components/Fri";
import Per from "../components/Per"
import Eng from "../components/Eng";
import Pic from "../components/admin/Pic";
import Floder from "../components/Floder";
import Flo from "../components/admin/Flo";
import Register from "../components/Register.vue";
import Vde from "../components/admin/Vde";
import Found from "../components/Found";
import Food from"../components/Fri.vue";
Vue.use(VueRouter)

const routes = [
  {
    path: '/success',
    component: success
  },
  {
    path: '/login',
    component: Login
  },
  // {
  //   path: '/',
  //
  //   redirect: '/login',
  //   children: [
  //    {path: '/login',component: Login} ,{path: '/register',component: Register}
  //    ]
  // },
  {
    path: '/register',
    component: Register
  },
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [
      { path:'/welcome', component: Welcome},{ path:'/user', component: User},{path: '/goods',component: Goods},{path: '/sport',component:Spo },{path: '/rights',component: Muc},{path:'/introduction',component: Eu},{path: '/friend',component: Fri},{path: '/message',component: Per},{path: '/calories',component: Eng},{path: '/reset',component: Floder},{path:'/found',component: Found},{path: '/food',component: Food}
    ],
  },
  {
    path: '/home',
    component: Home,
    redirect:'/user',
    children: [

      {path: '/user',component: User},{path: '/pic',component: Pic},{path: '/flo',component: Flo},{path: '/video',component: Vde}
    ]
  }

]

const router = new VueRouter({
  routes
})
const VueRouterPush = VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
// 挂载路由导航守卫
//  router.beforeEach((to, from, next) => {
//   // to:将要访问的路径
//    // from:从哪里访问的路径
//    // next:之后要做的任务，是一个函数
//    //    next（）放行， next（'/URL'）强制跳转的路径。
//     if (to.path == '/register') return next();
//
//   // 获取flag
//  const flagStr = window.sessionStorage.getItem("flag");// session取值
//   if (!flagStr) return next('/register');// 没登录去登录
//
//   next();
//  })
 // router.beforeEach((to, from, next) => {
//   // to:将要访问的路径
//   // from:从哪里访问的路径
//   // next:之后要做的任务，是一个函数
//   //    next（）放行， next（'/URL'）强制跳转的路径。
//   if (to.path == '/register') return next();// 访问路径为登录
//   // 获取flag
//   const flagStr = window.sessionStorage.getItem("flag");// session取值
//   if (!flagStr) return next('/register');// 没登录去登录
//
//
//
//   next();
// })

export default router// 暴露出去
